#!/bin/bash
# Changes the icon theme of the system
# To run: ./changeicon.sh SomeIconThemeName
# To see a list of installed icon themes: ./changeicon.sh
if [ -z "${1}" ]; then echo "Please pass an icon theme name:"$'\n'"  ${0} SomeThemeName"$'\n'"You can use these:";ls -l /usr/share/icons/ | grep ^d | awk '{print $9}';ls -l ~/.icons/ | grep ^d | awk '{print $9}'; exit 1; fi
if [ ! -d "/usr/share/icons/${1}" ] && [ ! -d "~/.icons/${1}" ]; then echo "The icon theme does not exist"; exit 2; fi
ICON_THEME="${1}"
if [ -f ~/.config/gtk-3.0/settings.ini ]; then
	if [ -n "$(grep 'gtk-icon-theme-name' ~/.config/gtk-3.0/settings.ini)" ]; then
		sed -i "s/gtk-icon-theme-name=\(.*\)/gtk-icon-theme-name=${ICON_THEME}/1" ~/.config/gtk-3.0/settings.ini
	else
		echo "gtk-icon-theme-name=${ICON_THEME}" >> ~/.config/gtk-3.0/settings.ini
	fi
else
	echo "[Settings]"$'\n'"gtk-icon-theme-name=${ICON_THEME}" > ~/.config/gtk-3.0/settings.ini
fi
if [ -f ~/.gtkrc-2.0 ]; then
	if [ -n "$(grep 'gtk-icon-theme-name' ~/.gtkrc-2.0)" ]; then
		sed -i "s/gtk-icon-theme-name=\(.*\)/gtk-icon-theme-name=\"${ICON_THEME}\"/1" ~/.gtkrc-2.0
	else
		echo "gtk-icon-theme-name=\"${ICON_THEME}\"" >> ~/.gtkrc-2.0
	fi
else
	echo "gtk-icon-theme-name=\"${ICON_THEME}\"" > ~/.gtkrc-2.0
fi
gsettings set org.gnome.desktop.interface icon-theme "${ICON_THEME}"

echo "Change is applied. You may have to restart apps to take changes effect."
